package com.zx.designpattern;

import android.app.Application;
import android.content.Context;

import com.midcent.leakcanarylibrary.LeakCanaryManager;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;

/**
 * @作者 Administrator
 * @创建时间 2018-03-10 15:10
 * @描述 BaseApplication
 * @修改时间 2018-03-10 15:10
 * @修改描述
 * @修改者 Administrator
 **/
public class BaseApplication extends Application {
    private static BaseApplication instance;

    public static Application getInstance() {
        if (instance == null) {
            throw new RuntimeException("BaseApplication is null,please restart your app");
        }
        return instance;
    }

    public static Context getAppContext() {
        return getInstance().getApplicationContext();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        Logger.addLogAdapter(new AndroidLogAdapter());

        //初始化内存泄漏检测
        LeakCanaryManager.getInstance().initLeakCanary(this);
    }
}
